
//
//  UIBarButtonItem+Extensions.swift
//  WeiBoAPP
//
//  Created by 张学飞 on 2018/12/29.
//  Copyright © 2018 zxf. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    /*
     *@Description: 创建UIBarButtonItem
     *@Params: title
     *@Return: <#返回#>
     */
    
    //遍历构造函数
    convenience  init(title: String,fontSize: CGFloat = 16,target:AnyObject?,action:Selector,isBack:Bool = false) {
        
        let btn:UIButton = UIButton(type: UIButton.ButtonType.custom)
        btn.setTitle(title, for: UIControl.State.normal)
        
        btn.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
        btn.setTitleColor(UIColor.orange, for: UIControl.State.normal)
        btn.addTarget(target, action: action, for: UIControl.Event.touchUpInside)
        
        if isBack {
           let imageName = "fanhui"
            btn.setImage(UIImage(named: imageName), for: UIControl.State.normal)
            btn.sizeToFit()
        }
        //实例化UIBarButtonItem
        self.init(customView:btn)
    }
    
}

